home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / SAT / myPlatform ƒ / sHMovPlatform.p < prev    next >
Encoding:
Text File  |  1994-07-26  |  2.8 KB  |  107 lines  |  [TEXT/PJMM]

  1. { Platform sprite, horizontally moving version (not faceless) }
  2.  
  3. unit sHMovPlatForm;
  4.  
  5. interface
  6.  
  7.     uses
  8.         SAT, sPlatForm, sMovPlatForm;
  9.  
  10.     procedure InitHMovPlatForm;
  11.     procedure SetupHMovPlatForm (me: SpritePtr);
  12.     procedure HandleHMovPlatForm (me: SpritePtr);
  13.     procedure HitHMovPlatForm (me, him: SpritePtr);
  14.  
  15. implementation
  16.  
  17.     procedure InitHMovPlatForm;
  18.         var
  19.             i: integer;
  20.     begin
  21. {platFace := GetFace(138); same as vertically moving version, we use the same!}
  22.     end;
  23.  
  24.     procedure SetupHMovPlatForm (me: SpritePtr);
  25.         var
  26.             r: Rect;
  27.             pol: PolyHandle;
  28.     begin
  29.         me^.speed.h := -1 + Rand(2) * 2;
  30.         me^.kind := -2; {Enemy kind}
  31.         me^.face := platFace;
  32.         SetRect(me^.hotRect, 0, 3, 60, 20);
  33.         me^.task := @HandleHMovPlatform;
  34.         me^.hittask := @HitHMovPlatform;
  35.     end;
  36.  
  37.     procedure HandleHMovPlatForm (me: SpritePtr);
  38.     begin
  39.         me^.position.h := me^.position.h + me^.speed.h;
  40.         if me^.position.h < 40 then
  41.             me^.speed.h := 1;
  42.         if me^.position.h > gSAT.offSizeH - 100 then
  43.             me^.speed.h := -1;
  44.  
  45. {Move!}
  46.         if me^.speed.h = 0 then
  47.             if me^.position.h > gSAT.offSizeH div 2 then
  48.                 me^.speed.h := -1
  49.             else
  50.                 me^.speed.h := 1;
  51.  
  52.         me^.layer := -me^.position.v;
  53.     end;
  54.  
  55.     procedure HitHMovPlatForm;
  56.         var
  57.             mini, i, min: integer;
  58.             diff: array[1..4] of integer;
  59.     begin
  60.         if him^.Task <> @HandlePlatForm then  {check for HandleMovPlatForm too?}
  61.             begin
  62.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);{TtoB}
  63.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);{BtoT}
  64.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);{LtoR}
  65.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);{RtoL}
  66.                 mini := 0;
  67.                 min := 10000;
  68.                 for i := 1 to 4 do
  69.                     if min > diff[i] then
  70.                         begin
  71.                             min := diff[i];
  72.                             mini := i;
  73.                         end;
  74.                 case mini of
  75.                     1: {floor}
  76.                         begin
  77.                             him^.position.v := him^.position.v - diff[1] + 1;
  78.                             him^.position.h := him^.position.h + me^.speed.h; {or perhaps him^speed?}
  79.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  80.                             if him^.speed.v > 0 then
  81.                                 him^.speed.v := 0;
  82.                         end;
  83.                     2: {cieling}
  84.                         begin
  85.                             him^.position.v := him^.position.v + diff[2] + 1;{me^.position.v + 17}
  86. {No signal here}
  87.                             if him^.speed.v < 0 then
  88.                                 him^.speed.v := -him^.speed.v;
  89.                         end;
  90.                     3: {left}
  91.                         begin
  92.                             him^.position.h := him^.position.h - diff[3] - 1;
  93.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  94.                             if him^.speed.h > 0 then
  95.                                 him^.speed.h := -him^.speed.h;
  96.                         end;
  97.                     4: {right}
  98.                         begin
  99.                             him^.position.h := him^.position.h + diff[4] + 1;{me^.position.h + 100}
  100.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  101.                             if him^.speed.h < 0 then
  102.                                 him^.speed.h := -him^.speed.h;
  103.                         end;
  104.                 end;{case}
  105.             end; {if}
  106.     end; {HitHMovPlatForm}
  107. end.{of unit}